<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<div class="container_12 clearfix leading">
    <div id="demo" class="clearfix">
        <table class="display" id="example">
            <thead>
            <tr>
                <th>选择</th>
                <th>工号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>部门</th>
                <th>职务</th>
                <th>职等职级</th>
                <th>入职时间</th>
                <th>${type == 'e_list' ? "离职时间" : "离职申请时间"}</th>
                <s:if test="#request.type == 'procedure'">
                <th style="width: 80px">签字单</th>
                </s:if>
                <s:if test="#request.type != 'e_list'">
                <th style=" width:80px">${type == "list" ? "详细信息" : "审核状况"}</th>
                </s:if>
                <s:if test="#request.type == 'procedure'">
                <th>离职手续</th>
                </s:if>
            </tr>
            </thead>
            <tbody>
            <s:if test="#request.applys == null or #request.applys.size() == 0">
                <tr class="gradeX"><td colspan='${type == 'procedure' ? "11" : "10"}'>暂无数据</td></tr>
            </s:if>
            <s:else>
                <s:iterator value="#request.applys" var="a" status="sta">
                <tr class='grade${sta.even ? "A" : "C"}'>
                    <td><input type="checkbox" id="form-updates" value="1"/></td>
                    <td>${a.work.workNo}</td>
                    <td>${a.work.baseId.name}</td>
                    <td>${a.work.baseId.sex == '0' ? "男" : "女"}</td>
                    <td><span id="GridView1_ctl04_Label">${a.work.organization.fullName}</span></td>
                    <td>${a.work.duty.dutyName}</td>
                    <td>${a.work.grade.gradeName}${apply.work.grade.gradeSort}</td>
                    <td>${a.work.baseId.entryDate} </td>
                    <s:if test="#request.type == 'e_list'">
                    <td><s:date name="#request.a.leaveDate" format="dd/MM/yyyy"/> </td>
                    </s:if>
                    <s:else>
                    <td><s:date name="#request.a.create_date" format="dd/MM/yyyy"/> </td>
                    </s:else>
                    <s:if test="#request.type == 'procedure'">
                    <td>
                        <span class="gradeX"><a href="#leave/procedure-print.xhtml?apply.id=${a.id}" class="button"><span class="icon icon-ok" style="background:url(${ctx}/images/img/printer.png)">&nbsp;</span>打印</a></span>
                    </td>
                    </s:if>
                    <s:if test="#request.type != 'e_list'">
                    <td class="gradeX">
                        <s:if test="#request.type == 'hr_audit'">
                            <s:if test="#request.a.hrStatus.toString() == 'wait_audit'">
                                <a class="button" href="#leave/apply-hr-audit-input.xhtml?apply.id=${a.id}"> <span style="background:url(${ctx}/images/img/error.png)" class="icon">&nbsp;</span>未审核 </a>
                            </s:if>
                            <s:elseif test="#request.a.hrStatus.toString() == 'pass_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>已过核</a>
                            </s:elseif>
                            <s:else>
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/exclamation.png)" class="icon">&nbsp;</span>未过核</a>
                            </s:else>
                        </s:if>
                        <s:elseif test="#request.type == 'audit'">
                            <s:if test="#request.a.status.toString() == 'wait_audit'">
                                <a class="button" href="#leave/apply-audit.xhtml?apply.id=${a.id}"> <span style="background:url(${ctx}/images/img/error.png)" class="icon">&nbsp;</span>未审核</a>
                            </s:if>
                            <s:elseif test="#request.a.status.toString() == 'within_audit'">
                                <a class="button" href="#leave/apply-audit.xhtml?apply.id=${a.id}"> <span style="background:url(${ctx}/images/img/information.png)" class="icon">&nbsp;</span>审核中</a>
                            </s:elseif>
                            <s:elseif test="#request.a.status.toString() == 'reject_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>未过核</a>
                            </s:elseif>
                            <s:elseif test="#request.a.status.toString() == 'pass_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>已过核</a>
                            </s:elseif>
                        </s:elseif>
                        <s:elseif test="#request.type == 'list'">
                            <a class="button" href="#employee/staff_view.xhtml?id=${a.work.id}"> <span class="icon icon-ok" style="background:url(${ctx}/images/img/zoom.png)">&nbsp;</span>查看</a>
                        </s:elseif>
                        <s:elseif test="#request.type == 'procedure'">
                            <s:if test="#request.a.status.toString() == 'wait_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/error.png)" class="icon">&nbsp;</span>未审核</a>
                            </s:if>
                            <s:elseif test="#request.a.status.toString() == 'within_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/information.png)" class="icon">&nbsp;</span>审核中</a>
                            </s:elseif>
                            <s:elseif test="#request.a.status.toString() == 'reject_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>未过核</a>
                            </s:elseif>
                            <s:elseif test="#request.a.status.toString() == 'pass_audit'">
                                <a class="button" href="javascript:void(0)"> <span style="background:url(${ctx}/images/img/accept.png)" class="icon">&nbsp;</span>已过核</a>
                            </s:elseif>
                        </s:elseif>
                    </td>
                    </s:if>
                    <s:if test="#request.type == 'procedure'">
                    <td style="width: 100px">
                        <span class="gradeX">
                            <a href="javascript:void(0)" onclick="onRealLeave('${a.id}')" class="button">
                                <s:if test="#request.a.leaveOffice == true">
                                    <span class="icon icon-ok" style="background:url(${ctx}/images/img/information.png)">&nbsp;</span><span id="apply_${a.id}">已完成</span>
                                </s:if>
                                <s:else>
                                    <span class="icon icon-ok" style="background:url(${ctx}/images/img/information.png)">&nbsp;</span><span id="apply_${a.id}">完成</span>
                                </s:else>
                            </a>
                        </span>
                    </td>
                    </s:if>
                </tr>
                </s:iterator>
            </s:else>
            </tbody>
        </table>
    </div>
</div>

<div class="clear"></div>

<script type="text/javascript">
    function onRealLeave(applyId){
        if($("#apply_"+applyId).html() == "已完成"){
            return;
        }
        if(applyId > 0){
            var url = "${ctx}/ajax/leave-office-apply-finish.xhtml?apply.id="+applyId;
            $.ajax(url, {
                type:"POST",
                dataType:"json",
                cache:false,
                success:function (result) {
                    if(result){
                        alert("离职已完成")
                        $("#apply_"+applyId).html("已完成")
                    }else{
                        alert("离职失败")
                    }
                },
                complete:function () {
                }
            });
        }
    }
</script>